package com.liuanbang.saro.sarodemo.util;

import android.view.Gravity;
import android.view.ViewGroup;

import com.liuanbang.saro.sarodemo.R;
import com.liuanbang.saro.sarodemo.base.AbstractDialog;
import com.liuanbang.saro.sarodemo.base.AnimEnum;
import com.liuanbang.saro.sarodemo.orther.picker.common.popup.BasicPopup;


/**
 * 通用弹窗工具
 */
public class DialogUtil {

    //宽度
    private int width = ViewGroup.LayoutParams.MATCH_PARENT;
    //高度
    private int height = ViewGroup.LayoutParams.WRAP_CONTENT;

    private AbstractDialog dialog;

    //获得弹窗工具实例
    public static DialogUtil getInstance() {
        DialogUtil dialogUtil = null;
        try {
            dialogUtil = DialogUtil.class.newInstance();
        } catch (Exception e) {
        }
        return dialogUtil;
    }

    //加载弹窗对象
    public DialogUtil load(AbstractDialog dialog) {
        this.dialog = dialog;
        dialog.setSize(BasicPopup.WRAP_CONTENT, BasicPopup.WRAP_CONTENT);
        return this;
    }

    //开启弹窗效果
    public DialogUtil show(AnimEnum animEnum) {
        switch (animEnum) {
            case BOTTOM:
                //底部动画效果
                dialog.setAnimationStyle(R.style.popup_window_bottom);
                // popupWindow.showAtLocation(parentView, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                dialog.setGravity(Gravity.BOTTOM);
                dialog.show();
            case CENTER:
                //中间动画效果
                dialog.setAnimationStyle(R.style.popup_window_center);
                //   popupWindow.showAtLocation(parentView, Gravity.CENTER | Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
                dialog.setGravity(Gravity.CENTER);
                dialog.show();
        }
        return this;
    }

    //关闭弹窗效果
    public void close() {
        dialog.dismiss();
    }
}
